<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ref官方推荐</title>
    <script src="../react/react.development.js"></script>
    <script src="../react/react-dom.development.js"></script>
    <script src="../react/prop-types.js"></script>
    <script src="../react/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
    class MyComp extends React.Component {
        refH1 = React.createRef()
        refH2 = React.createRef()

        ClickHandler () {
            console.log(this.refH1.current, this.refH2.current)
        }

        render () {
            return (
                <div>
                    <h1 ref={this.refH1}>大家好</h1>
                    <h2 ref={this.refH2}>我是React</h2>
                    <button onClick={this.ClickHandler.bind(this)}>点击</button>
                </div>
            )
        }
    }
    ReactDOM.render(<MyComp></MyComp>, document.getElementById('root'))
</script>
</body>
</html>
